<?php
require_once('TheAdmin.class.php');
$admin = new TheAdmin();
$host_path = ADMIN_HOST_PATH;
if(!isset($_REQUEST['act']))
{
	//登录页面
	?>
	<form action="<?php echo $host_path?>login.php?act=login" method="POST">
	用户名<input type="text" name="admin_user_name"><br/>
	密　码<input type="password" name="admin_user_pwd"><br/>
	<input type="submit" value="提交"><input type="reset" value="重置">
	</form>
	<?php
}else if(isset($_REQUEST['act'])&&$_REQUEST['act']=="login")
{
	//登录
	$admin_user_name = $_POST['admin_user_name'];
	$admin_user_pwd = $_POST['admin_user_pwd'];
	if(empty($admin_user_name) || empty($admin_user_pwd))
	{
		alertMsg2("重新填写",HOST_PATH."admin/login.php");
	}
	$admin_user_pwd = md5($admin_user_pwd);
	$where = "admin_user_name='{$admin_user_name}' AND admin_user_pwd='{$admin_user_pwd}' AND admin_user_state=1";
	$db = Factory::getDB("admin_user");
	$admin_user_temp = $db->getAll($where);
	if(empty($admin_user_temp))
	{
		//搜索本地用户表，改用户是否存在，如果存在则删除
		if($user_manager->check_user_name($admin_user_name))
		{
			//用户名，不存在
		}
		alertMsg2("用户名或者密码错误",HOST_PATH."admin/login.php");
	}
	$admin_user_arr = $admin_user_temp[0];
	$admin->userRequest->set('admin_user_id',$admin_user_arr['admin_user_id']);
	$admin->userRequest->set('admin_group_id',$admin_user_arr['admin_group_id']);
	$admin->userRequest->set('admin_user_permission_type',$admin_user_arr['admin_user_permission_type']);
	$admin->userRequest->set('admin_user_permission',$admin_user_arr['admin_user_permission']);
	admin_log($admin_user_arr['admin_user_id'],'login in',$where,2);
	alertMsg2("登录成功",ADMIN_HOST_PATH."index.php");
}else{
	//登出
	admin_log($admin->userRequest->get('admin_user_id'),'login out','',2);
	$admin->userRequest->free('admin_user_id');
	$admin->userRequest->free('admin_group_id');
	$admin->userRequest->free('admin_user_permission_type');
	$admin->userRequest->free('admin_user_permission');
	alertMsg2("登出成功",ADMIN_HOST_PATH."index.php");
}
?>